package com.bysj.servelt;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bysj.model.Comment;
import com.bysj.model.Evaluation;
import com.bysj.model.Order;
import com.bysj.service.CommentService;
import com.bysj.service.EvaluationService;
import com.bysj.service.OrderService;

/**
 * Servlet implementation class AdminOrderReplyServlet
 */
@WebServlet("/windowshoper/order_reply")
public class WindowshoperOrderReplyServlet extends HttpServlet {
	private OrderService oService = new OrderService();
	private CommentService cService = new CommentService();
	private EvaluationService eService = new EvaluationService();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int orderId = Integer.parseInt(request.getParameter("orderId"));

		Order order = oService.getOrder(orderId);
		order.getItemList().forEach(item -> {
			Evaluation evaluation = eService.getWindowshoperOrderEvaluation(orderId,item.getGoodsId());
			List<Evaluation> evaluations = new ArrayList<>();
			evaluations.add(evaluation);
			item.setEvaluations(evaluations);
		});
		request.setAttribute("order", order);

		Comment c = cService.getOrderComment(orderId);
		request.setAttribute("c", c);

		request.getRequestDispatcher("/windowshoper/reply.jsp").forward(request, response);
	}

}
